package com.ant.storage.controller;

import com.ant.storage.common.ResultPage;
import com.ant.storage.pojo.Allocation;
import com.ant.storage.service.IAllocationService;
import com.ant.storage.common.PageRecv;
import com.ant.storage.common.ResultVo;
import com.taobao.api.ApiException;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/allocation")
@Api(tags = "调拨申请接口")
public class AllocationController {

    @Autowired
    private IAllocationService allocationService;

    @ApiOperation(value = "添加调拨申请")
    @PostMapping("/addAllocation")
    public ResultVo addAllocation(@RequestBody Allocation allocation) throws NoSuchFieldException {
        allocationService.addAllocation(allocation);
        return ResultVo.success("插入成功");
    }

    @ApiOperation(value = "修改")
    @PostMapping("/updateAllocation")
    public ResultVo updateAllocation(@RequestBody Allocation allocation) throws NoSuchFieldException {
        allocationService.updateAllocation(allocation);
        return ResultVo.success("插入成功");
    }

    @ApiOperation(value = "调拨申请钉钉审批新增界面发起")
    @PostMapping("/addAllocationDingDing")
    @Transactional(rollbackFor = Exception.class)
    public ResultVo addAllocationDingDing(@RequestBody Allocation allocation) throws ApiException, NoSuchFieldException {
        allocationService.addAllocation(allocation);
        allocationService.addDingDing(allocation);
        return ResultVo.success("ok");
    }

    @ApiOperation(value = "调拨申请钉钉审批详情界面发起")
    @PostMapping("/addaAlLocationDingDing01")
    @Transactional(rollbackFor = Exception.class)
    public ResultVo addaAlLocationDingDing01(@RequestBody Allocation allocation) throws ApiException, NoSuchFieldException {
        allocationService.updateAllocation(allocation);
        allocationService.addDingDing(allocation);
        return  ResultVo.success("ok");
    }

    @ApiOperation(value = "调拨申请单查询详情")
    @GetMapping("/queryAllocationMessage")
    public ResultVo queryAllocationMessage(Integer allocation_id){
        return allocationService.queryAllocationMessage(allocation_id);
    }

    @ApiOperation(value = "调拨申请单查询")
    @PostMapping("/queryAllocation")
    public ResultPage queryAllocation(@RequestBody PageRecv<Allocation>pageRecv){
        return allocationService.queryAllocation(pageRecv);
    }

    @ApiOperation(value = "调拨申请单撤销")
    @PostMapping("/revokeAllocation")
    public ResultVo revokeAllocation(@RequestBody Allocation allocation) throws ApiException {
        return allocationService.revokeAllocation(allocation.getProcess_instance_id());
    }

}
